<?php
/**
 * 发布器-我的清单列表
 */

use Biz\service\wiki\Wiki as sWiki;
use Doraemon\cache\UserCounter;
use Doraemon\tools\ActionLog as tActionLog;
use Doraemon\tools\BlockType;
use Doraemon\tools\HhzClient;
use Doraemon\tools\StatSign;

class ListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;
    const IS_LOG_EXPOSE = 1;

    public function main()
    {
        $currUid = $this->uid;
        $uid = $this->getRequest()->getQuery('uid', 0);
        $page = $this->getRequest()->getQuery('page', 0);
        $pageName = $this->getRequest()->getQuery('page_name', 'inventory_page');
        $pageSize = 20;
        $platform = $this->getRequest()->getQuery('platform', '');
        if (!$uid) {
            $uid = $currUid;
        }
        $page = $page ?: 1;
        tActionLog::log($this->uid, [
            'uid' => $uid,
            'owner_uid' => $currUid,
            'page' => $page,
        ], tActionLog::BIZ_USER_WIKI_LIST);
        $list = sWiki::getUserWikiList($uid, $currUid, $page, $pageSize, $pageName);
        $list['list'] = \Biz\tools\helper\Common::getWikiList($list['list']);
        if ($platform == 'node') HhzClient::setClientVersion(StatSign::WIKI_UP_GRADE_VERSION_522);
        $list['list'] = StatSign::versionCompatible($list['list'], StatSign::WIKI_UP_GRADE_VERSION_522, BlockType::TYPE_WIKI, 'wiki');

        $counter = UserCounter::getOne($uid);
        $list['total'] = (int)$counter['relate_wiki'];

        $this->setSuccess($list);
    }
}